﻿/*
* (c) by Andreas Kreisl
*
* Sys Monitor - Plugin: phpp_kernel
* Version: 0.2
*
* License: creative commons BY-NC-SA
*/


// --------------------------------------------------------------------------------
// myPlugin Variables (required!)

myPlugins["phpp_kernel"] = new Object();
myPlugins["phpp_kernel"]["name"] = getLocalizedString2("phpp_kernel");
myPlugins["phpp_kernel"]["onlyonce"] = false;
myPlugins["phpp_kernel"]["newObject"] = function (NewSettings) { return new plugin_phpp_kernel_sensor(NewSettings); }

// --------------------------------------------------------------------------------
// The Sensore Object

function plugin_phpp_kernel_sensor(NewSettings) {
	// Required variables
	this.plugin = "phpp_kernel";
	this.settings = NewSettings;

	this.edit = plugin_phpp_kernel_edit;
	this.ReDraw = plugin_phpp_kernel_ReDraw;
	//this.Delete = plugin_phpp_kernel_Delete;
	this.Update = plugin_phpp_kernel_refresh;

	this.frame = new Frame();
	this.frame.window = main;
	this.frame.width = mod_sysmonitor_width;
	//this.frame.style.backgroundColor = "red";


	// Init Settings
	if(!this.settings.color) this.settings.color = "#FFFFFF";
	if(!this.settings.id)
		for(var i in PHPSysInfo)
			if(i) {
				this.settings.id = i;
				//break;
			}

	// The Sensore
	this.uptime = new class_TextLine(this.frame,0,"Kernel: ");
	this.uptime.label.color = this.settings.color;
	this.uptime.data.color = this.settings.color;

	// Update Timer
	var obj = this;
	plugin_phpp_kernel_refresh.call(obj);


	// Calculating sensore height (required!)
	this.frame.height = this.uptime.data.vOffset + (this.uptime.data.size * 1/3);
	return true;

// --------------------------------------------------------------------------------
// Helper Functions

	function plugin_phpp_kernel_edit() {
		var Drive_Edit_DialogFields = Array();
		var FieldID = -1;

		Drive_Edit_DialogFields[++FieldID] = new FormField();
		Drive_Edit_DialogFields[FieldID].title = getLocalizedString2("mod_sysm_plugin_color");
		Drive_Edit_DialogFields[FieldID].type = 'color';
		Drive_Edit_DialogFields[FieldID].defaultValue = this.settings.color;

		var SList = new Array();
		var SVal = new Array();
		for(var i in PHPSysInfo) {
			SList[SList.length] = PHPSysInfo[i]["Vitals"]["Hostname"];
			SVal[SVal.length] = i;
		}

		Drive_Edit_DialogFields[++FieldID] = new FormField();
		Drive_Edit_DialogFields[FieldID].title = getLocalizedString2("mod_sysm_plugin_php_host_source");
		Drive_Edit_DialogFields[FieldID].type = 'popup';
		Drive_Edit_DialogFields[FieldID].option = SList;
		Drive_Edit_DialogFields[FieldID].optionValue = SVal;
		Drive_Edit_DialogFields[FieldID].defaultValue = this.settings.id;


		var Drive_Edit_DialogResults = form(Drive_Edit_DialogFields, getLocalizedString2("mod_sysm_plugin_preftitle") + myPlugins[this.plugin]["name"]);
		if (Drive_Edit_DialogResults != null) {
			this.settings.color = Drive_Edit_DialogResults[0];
			this.uptime.label.color = this.settings.color;
			this.uptime.data.color = this.settings.color;


			this.settings.id = Drive_Edit_DialogResults[1];

			plugin_phpp_kernel_refresh.call(obj);
		}
		delete Drive_Edit_DialogFields;
		return true;
	}

	function plugin_phpp_kernel_refresh() {
		if(PHPSysInfo[this.settings.id]) {
			this.uptime.data.data = PHPSysInfo[this.settings.id]["Vitals"]["Kernel"];
			return true;
		} else {
			this.uptime.data.data = "---";
		}
	}


	function plugin_phpp_kernel_ReDraw() {
		this.frame.width = mod_sysmonitor_width;
		this.uptime.size = mod_sysmonitor_size;
		this.frame.height = this.uptime.data.vOffset + (this.uptime.data.size * 1/3);
		return true;
	}

	function plugin_phpp_kernel_Delete() {
		return true;
	}

}

// --------------------------------------------------------------------------------
// The END